﻿using Microsoft.IdentityModel.Tokens;
using System.Text;

var s = "{\"http://schemas.microsoft.com/ws/2008/06/identity/claims/userdata\":{\"LoginId\":\"8a5c6990-d9d8-4d6b-aa8d-8dcb66d8c9e6\",\"UserId\":\"7198\",\"UserName\":\"杜小梅\",\"CompanyId\":\"2107081443070161157\",\"DeptId\":\"2107081622576651391\",\"WorkType\":\"巡检员\",\"JobNumber\":\"7198\",\"ChangePasswordDate\":\"2024-11-25T10:38:01.677\",\"LoginTime\":1735122819142},\"PasswordExpireDays\":365,\"exp\":1737714819}";

var sAry = Encoding.UTF8.GetBytes(s);

//得到的结果：eyJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3VzZXJkYXRhIjp7IkxvZ2luSWQiOiI4YTVjNjk5MC1kOWQ4LTRkNmItYWE4ZC04ZGNiNjZkOGM5ZTYiLCJVc2VySWQiOiI3MTk4IiwiVXNlck5hbWUiOiLmnZzlsI_mooUiLCJDb21wYW55SWQiOiIyMTA3MDgxNDQzMDcwMTYxMTU3IiwiRGVwdElkIjoiMjEwNzA4MTYyMjU3NjY1MTM5MSIsIldvcmtUeXBlIjoi5beh5qOA5ZGYIiwiSm9iTnVtYmVyIjoiNzE5OCIsIkNoYW5nZVBhc3N3b3JkRGF0ZSI6IjIwMjQtMTEtMjVUMTA6Mzg6MDEuNjc3IiwiTG9naW5UaW1lIjoxNzM1MTIyODE5MTQyfSwiUGFzc3dvcmRFeHBpcmVEYXlzIjozNjUsImV4cCI6MTczNzcxNDgxOX0
var base64Str1 = Base64UrlEncoder.Encode(sAry);

//得到的结果：eyJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3VzZXJkYXRhIjp7IkxvZ2luSWQiOiI4YTVjNjk5MC1kOWQ4LTRkNmItYWE4ZC04ZGNiNjZkOGM5ZTYiLCJVc2VySWQiOiI3MTk4IiwiVXNlck5hbWUiOiLmnZzlsI/mooUiLCJDb21wYW55SWQiOiIyMTA3MDgxNDQzMDcwMTYxMTU3IiwiRGVwdElkIjoiMjEwNzA4MTYyMjU3NjY1MTM5MSIsIldvcmtUeXBlIjoi5beh5qOA5ZGYIiwiSm9iTnVtYmVyIjoiNzE5OCIsIkNoYW5nZVBhc3N3b3JkRGF0ZSI6IjIwMjQtMTEtMjVUMTA6Mzg6MDEuNjc3IiwiTG9naW5UaW1lIjoxNzM1MTIyODE5MTQyfSwiUGFzc3dvcmRFeHBpcmVEYXlzIjozNjUsImV4cCI6MTczNzcxNDgxOX0=
var convertToBase64 = Convert.ToBase64String(sAry);

Console.WriteLine(base64Str1 == convertToBase64); //两个结果不同，使用 Base64UrlEncoder.Encode 转换的结果是错误的